﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NeuralNetworkComponents
{
    public class ActivationNeuron : Neuron
    {

	    public Double Threshold { get; set; }
		public IActivationFunction ActivationFunction { get; protected set; }
		public ActivationNeuron( int inputs, IActivationFunction function ) 
            : base( inputs )
		{
            this.ActivationFunction = function;
		}

		public override void Randomize( )
		{
			base.Randomize( );
			Threshold = Randomizer.NextDouble( ) * ( RandRange.Length ) + RandRange.Min;
		}

		public override Double Compute( Double[] input )
		{
			if ( input.Length != InputsCount )
				throw new ArgumentException( );

			Double sum = 0.0;

			for ( int i = 0; i < InputsCount; i++ )
			{
				sum += Weights[i] * input[i];
			}
			sum += Threshold;

			return ( Output = ActivationFunction.Function( sum ) );
		}
    }
}
